package com.zhou.core.logana;

/**
 * Created by zhouyongjun on 2020/6/12
 */
public class LogAnaResult {
    public static final LogAnaResult RESULT_SUCC = new LogAnaResult((byte)0);
    public static final LogAnaResult  RESULT_FAIL = new LogAnaResult((byte)1);

    private byte result;//0:�ɹ���1ʧ��
    private String msg;
    Object data;
    /**
     *
     * @param result 0:�ɹ���1ʧ��
     */
    private LogAnaResult(byte result)
    {
        this.result = result;
    }

    /**
     * ����ʧ�ܽ�������
     * @param msg: ʧ����Ϣ
     * @return
     */
    public static  LogAnaResult createFailResult(String msg)
    {
        return createFailResult(msg, null);
    }

    /**
     * ����ʧ�ܽ�������
     * @param msg: ʧ����Ϣ
     * @param data: ���ش��Ĳ�����Ϣ
     * @return
     */
    public static <T> LogAnaResult createFailResult(String msg, T data)
    {
        LogAnaResult result = new LogAnaResult((byte)1);
        result.msg = msg;
        result.data = data;
        return result;
    }

    /**
     *  * �����ɹ���������
     * @param msg: ʧ����Ϣ
     * @return
     */
    public static  LogAnaResult createSucLogAnaResult(String msg)
    {
        return createFailResult(msg, null);
    }

    /**
     * �����ɹ���������
     * @param msg: ʧ����Ϣ
     * @param data: ���ش��Ĳ�����Ϣ
     * @return
     */
    public static <T> LogAnaResult createSucLogAnaResult(String msg, T data)
    {
        LogAnaResult result = new LogAnaResult((byte)0);
        result.msg = msg;
        result.data = data;
        return result;
    }


    public String getMsg() {
        return msg;
    }


    public void setMsg(String msg) {
        this.msg = msg;
    }


    public <T> T getData() {
        return (T)data;
    }


    public void setData(LogRecord data) {
        this.data = data;
    }

    /**
     *
     * @return 0:�ɹ���1:ʧ��
     */
    public byte getResult() {
        return result;
    }


    public boolean isSucc()
    {
        return result == RESULT_SUCC.result;
    }

    public boolean isFail()
    {
        return result == RESULT_FAIL.result;
    }
}
